<?php
/***********************************************************************
 * @package     IvanEngine
 * @subpackage  Plugin
 * @author      Ivan <ivanzx@msn.com>
 * @created     2010-06-27
 ***********************************************************************/
if(defined("PLUGIN_ACTION_HOMEPAGE"))
    die("Redefinition macro in :".__FILE__."(".__LINE__.")");
define("PLUGIN_ACTION_HOMEPAGE", true);

class CActionHomePage extends CAction
{
    protected 
        $m_isInitPage   = false;
    public function DoRequisite(CRequest & $request)
    {
        $pluginPath = HFile::AToR($this->m_plugin->GetPath());
        $includePath= HFile::AToR(M_ENGINE_PATH);
        $this->Set('title', $this->m_i18n->Get('title'));
        $this->Set('jsArray', array(
            HUrl::U($includePath).'JS/Framework.js',
            HUrl::U($pluginPath).'View/JS/Requisite.js')
        );
        
        $this->Set('cssArray', array(
            HUrl::U(HFile::AToR(CThemesManager::Get()->GetCurThemePath()))
            )
        );
    }
    
    public function DoIndex(CRequest & $request)
    {
        $this->GetView()->SetWindow('main_header', false);
        $this->GetView()->SetRenderMode(CView::RM_APPEND);
        
        //$winModifier    = new CWindowModifier('window2', $this->GetView());
        //$winModifier->Set(CWindow::WA_POSX, 1);
        //$winModifier->Set(CWindow::WA_POSY, 200);
        //$winModifier->Execute();
        
        $plugins    = CPluginManager::Get()->LoadPlugins();
        foreach ( $plugins as $plugin ){
            if( $plugin->GetName() != 'Debugger' ){
                CContext::Get()->GetController()->Forward($plugin->GetName());
            }
        }
    }
    
    public function PreRender($actionName, $request)
    {
        if( $actionName == 'Requisite' )
        {
            $this->GetView()->AddContent(
                CPrinter::Get()->GetRoot()->GetContent(), true);
            CPrinter::Get()->GetRoot()->SetContent('');
        }
    }
    
    public function PostRender($actionName, $request)
    {
        if( $actionName == 'Requisite' )
       {            
            $this->m_isInitPage   = true;
            if( defined('_DEBUG') ){
                $this->GetView()->Clear();
                $this->m_plugin->ExecuteAction('Index', $request);
            }
        }
    }
}
?>
